package com.weilx959.spt.plugin.e2sp.model.statement;

import com.weilx959.spt.plugin.e2sp.constant.SQLType;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;
import lombok.experimental.SuperBuilder;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>检查约束语句</p>
 *
 * @author weilx
 * @since 2024-05-02
 */
@Data
@SuperBuilder
@NoArgsConstructor
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class CheckStatement extends ParentStatement {
    /**
     * SQL格式化模板
     */
    private String template;

    private DeleteStatement deleteStatement;

    private List<InsertStatement> insertStatements;

    public CheckStatement(ParentStatement parentStatement) {
        super(parentStatement);
    }

    public CheckStatement(ParentStatement parentStatement, String template) {
        super(parentStatement);
        this.template = template;
    }

    public CheckStatement addInsertStatement(InsertStatement insertStatement) {
        if (insertStatements == null) {
            insertStatements = new ArrayList<>();
        }
        insertStatements.add(insertStatement);
        return this;
    }

    @Override
    public SQLType getType() {
        return SQLType.CHECK;
    }
}
